package com.example.mydownloader.mymodule.http

import okhttp3.Interceptor
import okhttp3.Response

/**
 * @Author: Wallace
 * @Description: 文件描述
 * @Date: 2022/1/5 22:09
 * @Modified: By yyyy-MM-dd
 */
object TimeStampInterceptor : Interceptor {
    override fun intercept(chain: Interceptor.Chain): Response {
        var request = chain.request()
        val timeStamp = request.header("TimeStamp")
        if (timeStamp == null) {
            request = request.newBuilder()
                .addHeader("TimeStamp", (System.currentTimeMillis().toString()))
                .build()
        }
        return chain.proceed(request)
//        val receivedTimeStamp = response.receivedResponseAtMillis
//        val currentTimeStamp = System.currentTimeMillis()
//        val interval = currentTimeStamp.minus(receivedTimeStamp)
//        // 拒接两分钟前的响应
//        if (0 <= interval && interval < TimeUnit.MINUTES.toMillis(2)) {
//            return response
//        }else{
//
//        }
//        return
    }
}